package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Scenic;
import cn.wolfcode.trip.base.domain.Ticket;
import cn.wolfcode.trip.base.mapper.ScenicMapper;
import cn.wolfcode.trip.base.mapper.TicketMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.ScenicQueryObject;
import cn.wolfcode.trip.base.service.IScenicService;
import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScenicServiceImpl implements IScenicService {

    @Autowired
    private ScenicMapper scenicMapper;


    @Autowired
    private TicketMapper ticketMapper;

    public PageInfo queryForApp(ScenicQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Scenic> list = scenicMapper.selectForAppList(qo);
        return new PageInfo(list);
    }

    public List<Scenic> queryForHot(Integer state) {
        return scenicMapper.selectHotAndPrice(state);
    }

    public Scenic get(Long id) {
        return scenicMapper.selectByPrimaryKey(id);
    }

    public List<Ticket> getTicket(Long id) {
        return ticketMapper.selectAll(id);
    }

    public List<Scenic> listAll() {
        return scenicMapper.selectAll();
    }

    public PageInfo<Scenic> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Scenic> list = scenicMapper.selectForList(qo);
        return new PageInfo(list);
    }

    public void saveOrUpdate(Scenic scenic) {
        if (scenic.getId() != null) {
            scenicMapper.updateByPrimaryKey(scenic);
        } else {
            scenicMapper.insert(scenic);
        }
    }

    public List listHistory() {
        return scenicMapper.listHistory();
    }

    public void insertHistory(String keyword) {
        scenicMapper.insertHistory(keyword);
    }

}
